package org.liuyuantao.patterns.observer.jdk;

import java.util.Observable;

/**
 * 这里需要继承Observable,因为jdk提供了添加观察者和移除观察者的相关方法
 */
public class WeatherData extends Observable {
    private float mTemperatrue;
    private float mPressure;
    private float mHumidity;

    public float getTemperature() {
        return mTemperatrue;

    }

    public float getPressure() {
        return mPressure;

    }

    public float getHumidity() {
        return mHumidity;

    }


    public void dataChange() {
        //这里需要调用Observable的setChanged,告诉数据修改了
        this.setChanged();
        this.notifyObservers(new Data(getTemperature(), getPressure(), getHumidity()));

    }


    public void setData(float mTemperatrue, float mPressure, float mHumidity) {
        this.mTemperatrue = mTemperatrue;
        this.mPressure = mPressure;
        this.mHumidity = mHumidity;
        dataChange();
    }

    public class Data {
        public float mTemperatrue;
        public float mPressure;
        public float mHumidity;

        public Data(float mTemperatrue, float mPressure, float mHumidity) {
            this.mTemperatrue = mTemperatrue;
            this.mPressure = mPressure;
            this.mHumidity = mHumidity;
        }

        public float getmTemperatrue() {
            return mTemperatrue;
        }

        public void setmTemperatrue(float mTemperatrue) {
            this.mTemperatrue = mTemperatrue;
        }

        public float getmPressure() {
            return mPressure;
        }

        public void setmPressure(float mPressure) {
            this.mPressure = mPressure;
        }

        public float getmHumidity() {
            return mHumidity;
        }

        public void setmHumidity(float mHumidity) {
            this.mHumidity = mHumidity;
        }
    }

}
